// Copyright 2024 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

////////////////////////////////////////////////////////////////////////////////
// File generated by 'tools/src/cmd/gen' using the template:
//   src/tint/lang/glsl/builtin_fn.cc.tmpl
//
// To regenerate run: './tools/run gen'
//
//                       Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////

#include "src/tint/lang/glsl/builtin_fn.h"

namespace tint::glsl {

const char* str(BuiltinFn i) {
    switch (i) {
        case BuiltinFn::kNone:
            return "<none>";
        case BuiltinFn::kLength:
            return "length";
        case BuiltinFn::kBarrier:
            return "barrier";
        case BuiltinFn::kMemoryBarrierBuffer:
            return "memoryBarrierBuffer";
        case BuiltinFn::kMemoryBarrierImage:
            return "memoryBarrierImage";
        case BuiltinFn::kAtomicCompSwap:
            return "atomicCompSwap";
        case BuiltinFn::kAtomicSub:
            return "atomicSub";
        case BuiltinFn::kFloatBitsToInt:
            return "floatBitsToInt";
        case BuiltinFn::kFloatBitsToUint:
            return "floatBitsToUint";
        case BuiltinFn::kIntBitsToFloat:
            return "intBitsToFloat";
        case BuiltinFn::kUintBitsToFloat:
            return "uintBitsToFloat";
        case BuiltinFn::kBitCount:
            return "bitCount";
        case BuiltinFn::kBitfieldExtract:
            return "bitfieldExtract";
        case BuiltinFn::kBitfieldInsert:
            return "bitfieldInsert";
        case BuiltinFn::kPackFloat2X16:
            return "packFloat2x16";
        case BuiltinFn::kUnpackFloat2X16:
            return "unpackFloat2x16";
        case BuiltinFn::kAbs:
            return "abs";
        case BuiltinFn::kAny:
            return "any";
        case BuiltinFn::kAll:
            return "all";
        case BuiltinFn::kDot:
            return "dot";
        case BuiltinFn::kMix:
            return "mix";
        case BuiltinFn::kModf:
            return "modf";
        case BuiltinFn::kFrexp:
            return "frexp";
        case BuiltinFn::kTexture:
            return "texture";
        case BuiltinFn::kTextureOffset:
            return "textureOffset";
        case BuiltinFn::kTextureLod:
            return "textureLod";
        case BuiltinFn::kExtTextureLod:
            return "extTextureLod";
        case BuiltinFn::kTextureLodOffset:
            return "textureLodOffset";
        case BuiltinFn::kExtTextureLodOffset:
            return "extTextureLodOffset";
        case BuiltinFn::kTextureGrad:
            return "textureGrad";
        case BuiltinFn::kTextureGradOffset:
            return "textureGradOffset";
        case BuiltinFn::kTextureGather:
            return "textureGather";
        case BuiltinFn::kTextureGatherOffset:
            return "textureGatherOffset";
        case BuiltinFn::kTextureSize:
            return "textureSize";
        case BuiltinFn::kImageSize:
            return "imageSize";
        case BuiltinFn::kTexelFetch:
            return "texelFetch";
        case BuiltinFn::kImageLoad:
            return "imageLoad";
        case BuiltinFn::kImageStore:
            return "imageStore";
        case BuiltinFn::kLessThan:
            return "lessThan";
        case BuiltinFn::kLessThanEqual:
            return "lessThanEqual";
        case BuiltinFn::kGreaterThan:
            return "greaterThan";
        case BuiltinFn::kGreaterThanEqual:
            return "greaterThanEqual";
        case BuiltinFn::kEqual:
            return "equal";
        case BuiltinFn::kNotEqual:
            return "notEqual";
    }
    return "<unknown>";
}

tint::core::ir::Instruction::Accesses GetSideEffects(BuiltinFn fn) {
    switch (fn) {
        case BuiltinFn::kBarrier:
        case BuiltinFn::kMemoryBarrierBuffer:
        case BuiltinFn::kMemoryBarrierImage:
        case BuiltinFn::kAtomicCompSwap:
        case BuiltinFn::kAtomicSub:
            return core::ir::Instruction::Accesses{core::ir::Instruction::Access::kLoad,
                                                   core::ir::Instruction::Access::kStore};

        case BuiltinFn::kTexture:
        case BuiltinFn::kTextureOffset:
        case BuiltinFn::kTextureLod:
        case BuiltinFn::kExtTextureLod:
        case BuiltinFn::kTextureLodOffset:
        case BuiltinFn::kExtTextureLodOffset:
        case BuiltinFn::kTextureGrad:
        case BuiltinFn::kTextureGradOffset:
        case BuiltinFn::kTextureGather:
        case BuiltinFn::kTextureGatherOffset:
        case BuiltinFn::kTexelFetch:
        case BuiltinFn::kImageLoad:
            return core::ir::Instruction::Accesses{core::ir::Instruction::Access::kLoad};

        case BuiltinFn::kImageStore:
            return core::ir::Instruction::Accesses{core::ir::Instruction::Access::kStore};

        case BuiltinFn::kLength:
        case BuiltinFn::kFloatBitsToInt:
        case BuiltinFn::kFloatBitsToUint:
        case BuiltinFn::kIntBitsToFloat:
        case BuiltinFn::kUintBitsToFloat:
        case BuiltinFn::kBitCount:
        case BuiltinFn::kBitfieldExtract:
        case BuiltinFn::kBitfieldInsert:
        case BuiltinFn::kPackFloat2X16:
        case BuiltinFn::kUnpackFloat2X16:
        case BuiltinFn::kAbs:
        case BuiltinFn::kAny:
        case BuiltinFn::kAll:
        case BuiltinFn::kDot:
        case BuiltinFn::kMix:
        case BuiltinFn::kModf:
        case BuiltinFn::kFrexp:
        case BuiltinFn::kLessThan:
        case BuiltinFn::kLessThanEqual:
        case BuiltinFn::kGreaterThan:
        case BuiltinFn::kGreaterThanEqual:
        case BuiltinFn::kEqual:
        case BuiltinFn::kNotEqual:
        case BuiltinFn::kTextureSize:
        case BuiltinFn::kImageSize:
        case BuiltinFn::kNone:
            break;
    }
    return core::ir::Instruction::Accesses{};
}

}  // namespace tint::glsl
